<?php
//后台登陆控制
include_once('admin_global.php');
$db->Get_user_shell_check($uid, $shell);   //检测用户是否登录
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>文章管理</title>
    <link rel="stylesheet" href="css/right.css" type="text/css" />
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/bggl.js" type="text/javascript"></script>
</head>
<script>
    function delNews_check()
    {
        if (window.confirm("文章删除后不能恢复，你确定要删除这篇文章吗？"))
            return true;
        else
            return false;
    }
</script>
<?php
//加入一级栏目导航
$sql = "SELECT id,cateName FROM category WHERE catePID=0";
$query = $db->query($sql);
while ($row = $db->fetch_array($query)) {
    $nav[] = $row;
}

/* 分页显示文章 */
$page_size = 12;  //每页显示的条数
$pageCurrent = @$_GET["page"];  //当前页数
if (!$pageCurrent){
    $pageCurrent = 1; //如果没设定页数默认是第一页
}
//查询出数据库中所有文章
$userName=$_SESSION['userName'];
if (isset($_GET['cateID'])) {
    $cateID = $_GET['cateID'];      //获得栏目ID
    //判断它是否有子栏目
    $sql = "SELECT * FROM category WHERE catePID=$cateID";
    $query = $db->query($sql);
    if ($db->db_num_rows($query) > 0) {
        $sql = "SELECT a.newsID,a.newsTitle,a.newsAuthor,a.newsSource,a.newsSendTime,a.newsUpdateTime,a.newsHits,a.isTop,a.isRed,b.id,b.cateName FROM news AS a,
                category AS b WHERE b.catePID=$cateID AND a.newsCID=b.id AND newsAuthor='$userName' ORDER BY a.newsSendTime DESC";
        $query = $db->query($sql);
        $sql_page=$sql . " LIMIT " . ($pageCurrent - 1) * $page_size . "," . $page_size;
        $query_page=$db->query($sql_page);
    } else {
        $sql = "SELECT a.newsID,a.newsTitle,a.newsAuthor,a.newsSource,a.newsSendTime,a.newsUpdateTime,a.newsHits,a.isTop,a.isRed,b.id,b.cateName FROM news AS a,
                category AS b WHERE b.id=$cateID AND a.newsCID=$cateID AND newsAuthor='$userName' ORDER BY a.newsSendTime DESC";
        $query = $db->query($sql);
        $sql_page=$sql . " LIMIT " . ($pageCurrent - 1) * $page_size . "," . $page_size;
        $query_page=$db->query($sql_page);
    }
} else {
    $cateID = 0;
    $sql = "SELECT a.newsID,a.newsTitle,a.newsAuthor,a.newsSource,a.newsSendTime,a.newsUpdateTime,a.newsHits,a.isTop,a.isRed,b.id,b.cateName FROM news AS a,
                category AS b WHERE b.id=a.newsCID AND newsAuthor='$userName' ORDER BY a.newsSendTime DESC";
    $query = $db->query($sql);
    $sql_page=$sql . " LIMIT " . ($pageCurrent - 1) * $page_size . "," . $page_size;
    $query_page=$db->query($sql_page);
}
//将查询出来的文章放入数组
$data = array();              //$data存储查询出来的所有文章，预设为空，防止某个栏目下没有文章时出错
while ($row = $query->fetch_array()) {
    $data[] = $row;
}

//分页查询也存入数组
$newslist = array();          //$newslist存储分页查询出来的文章，预设为空，防止某个栏目下没有文章时出错
while ($row = $query_page->fetch_array()) {
    $newslist[] = $row;
}
$nums = count($data);   //总条数
$sub_pages = $nums / $page_size + 1;  //得到当前是第几页
/* 分页显示结束 */

//显示当前栏目位置
if ($cateID == 0) {
    $cateName = "";
} else {
    $sql="SELECT * FROM category WHERE id=$cateID";
    $query = $db->query($sql);
    while ($row = $db->fetch_array($query)) {
        $cateName = $row['cateName'];
    }
}
?>
<body>
<div id="right_main">
    <div class="right_content">
        <div class="right_top_menu">
            <h3>
                栏目导航：
                <?php echo "|"; ?>
                <?php foreach ($nav as $row) { ?>
                    <?php echo "<a href=listMyNews.php?cateID=" . $row['id']."&newsAuthor=" .$userName. ">" . $row['cateName'] . "</a>" . " |"; ?>
                <?php }; ?>
            </h3>
        </div>
        <div class="right_center_content">
            <form id="form1" method="post" action="">
                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td valign="top" >
                            <div class="txl_search">&nbsp;&nbsp;您现在的位置：
                                <?php if($cateID==0){; ?>
                                    文章管理 >> <a href="listMyNews.php">我发布的文章</a>
                                <?php }else{; ?>
                                    文章管理 >> <a href="listMyNews.php">我发布的文章</a> >> <a href="listMyNews.php?cateID=<?php echo $cateID; ?>" ><?php echo $cateName; ?></a>
                                <?php }; ?>
                            </div>
                            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="fg_table txl_table" id="table1">
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="35%">文章标题</th>
                                    <th width="7%">作者</th>
                                    <th width="7%">来源</th>
                                    <th width="10%">发布时间</th>
                                    <th width="10%">修改时间</th>
                                    <th width="5%">浏览次数</th>
                                    <th width="5%">是否置顶</th>
                                    <th width="5%">是否加红</th>
                                    <th width="3%">修改</th>
                                    <th width="3%">删除</th>
                                </tr>
                                <?php foreach ($newslist as $row) { ;?>
                                    <tr>
                                        <td><?php echo $row['newsID']; ?></td>
                                        <td align="left"><a href=""></a><?php echo $row['newsTitle']; ?></td>
                                        <td><?php echo $row['newsAuthor']; ?></td>
                                        <td><?php echo $row['newsSource']; ?></td>
                                        <td><?php echo date("Y-m-d H:i:s", $row['newsSendTime']); ?></td>
                                        <td><?php echo date("Y-m-d H:i:s", $row['newsUpdateTime']); ?></td>
                                        <td><?php echo $row['newsHits']; ?></td>
                                        <td><?php if($row['isTop']==1){echo '是';}else{echo '否';};?></td>
                                        <td><?php if($row['isRed']==1){echo '是';}else{echo '否';};?></td>
                                        <td><a href="editNews.php?newsID=<?php echo $row['newsID']; ?>"><img src="images/adj_bg.gif" width="15" height="15" border="0" /></a></td>
                                        <td><a href="delNews.php?newsID=<?php echo $row['newsID']; ?>" onclick="javascript:return delNews_check();"><img src="images/del2.gif" width="16" height="16" border="0" /></a></td>
                                    </tr>
                                <?php }; ?>
                                <tr>
                                    <td colspan="10" style="color:#0351a1; font-weight:normal;border:none">
                                        <?php echo"共有".$nums."篇文章";?>&nbsp;&nbsp;
                                        <?php $p = new SubPages($page_size, $nums, $pageCurrent, $sub_pages, "listMyNews.php?page=", 2); ?>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
</body>
</html>
